package cn.broadsense.common.config;

import cn.broadsense.common.utils.spring.SpringUtils;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Minio配置
 *
 * @author pengxin
 * @date 2022-08-16 11:25
 */

@Data
@Component
public class MinioConfig {

    /**
     * 注入minio 客户端
     *
     * @return
     */
    @Bean
    @ConditionalOnProperty(name = "minio.url")
    public MinioClient minioClient(MinioProfile profile) {

        return MinioClient.builder()
                .endpoint(profile.getUrl())
                .credentials(profile.getAccessKey(), profile.getSecretKey())
                .build();
    }

    public static String getBucketName() {
        return SpringUtils.getBean(MinioProfile.class).getBucketName();
    }
}
